package com.liu.qqRobot.myself.service.impl;

import com.liu.common.content.RedisKeyInterface;
import com.liu.qqRobot.myself.service.PollingCircuitService;
import jakarta.annotation.Resource;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class PollingCircuitServiceImpl implements PollingCircuitService {

    @Resource
    private RedisTemplate<String, String> redisTemplate;

    @Override
    public void pollingCircuit() {
        String circuitPolling = redisTemplate.opsForValue().get(RedisKeyInterface.HARD_CIRCUIT_POLLING_REDIS_KEY);
        int nextPolling = 1;
        if (circuitPolling != null) {
            int currentPolling = Integer.parseInt(circuitPolling);
            nextPolling = currentPolling + 1;
            if (nextPolling > 8) {
                nextPolling = 1;
            }
        }
        redisTemplate.opsForValue().set(RedisKeyInterface.HARD_CIRCUIT_POLLING_REDIS_KEY, String.valueOf(nextPolling));
        circuitPolling = redisTemplate.opsForValue().get(RedisKeyInterface.ORDINARY_CIRCUIT_POLLING_REDIS_KEY);
        nextPolling = 1;
        if (circuitPolling != null) {
            int currentPolling = Integer.parseInt(circuitPolling);
            nextPolling = currentPolling + 1;
            if (nextPolling > 11) {
                nextPolling = 1;
            }
        }
        redisTemplate.opsForValue().set(RedisKeyInterface.ORDINARY_CIRCUIT_POLLING_REDIS_KEY, String.valueOf(nextPolling));
    }
}
